package com.zshan.clinic.web.scheduler;

import com.zshan.clinic.admin.service.medical.ClinicFollowupService;
import com.zshan.clinic.admin.service.stat.ClinicPerformanceService;
import com.zshan.clinic.admin.service.stock.StockDrugService;
import com.zshan.clinic.common.constant.CommonConstant;
import com.zshan.clinic.common.util.date.DateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

/**
 * 定时任务
 */
@Component
@Slf4j
public class ClinicScheduler {

    @Autowired
    private ClinicFollowupService clinicFollowupService;

    @Autowired
    private StockDrugService stockDrugService;

    @Autowired
    private ClinicPerformanceService clinicPerformanceService;

    /**
     * 每天下午17点发送随访提醒
     */
    @Scheduled(cron = "0 0 17 * * ?")
    public void followupReminder() {
        clinicFollowupService.followupReminder(LocalDate.now());
    }
    /**
     * 每天早上八点发送库存不足预警
     */
    @Scheduled(cron = "0 0 8 * * ?")
    public void stockWarning() {
        stockDrugService.stockWarning();
    }

    /**
     * 每天凌晨一点业绩统计
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void clinicPerformanceStat() {
        LocalDate yesterday = DateTimeUtils.subDays(LocalDate.now(), CommonConstant.DEFAULT_1);
        clinicPerformanceService.clinicPerformanceStat(yesterday);
    }


//    @Scheduled(cron = "0 */1 * * * ? ")
//    public void cronTask() {
//        System.out.println("Cron task executed at " + new Date());
//    }
}
